package com.qf.controller;

import com.qf.pojo.City;
import com.qf.SelfClass.Citys;
import com.qf.SelfClass.ResponseBody2;
import com.qf.SelfClass.ResponseData1;
import com.qf.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author Mr.Liu
 * @date 2021/12/15 11:51
 */
@RequestMapping("/city")
@Controller
public class CityController {
    /**
     * 查找所有城市
     */
    @Autowired
    private CityService cityService;
    @ResponseBody
    @RequestMapping("/findAllCity")
    public ResponseData1 findAllCity(@RequestParam Integer pid){
        List<City> citys = cityService.findAllCity(pid);
        return new ResponseData1(1,citys);
    }

    /**
     * 查找租车和还车城市
     * @param getid
     * @param backid
     * @return
     */
    @ResponseBody
    @RequestMapping("/findTwoCity")
    public ResponseBody2 find2City(@RequestParam("getid") Integer getid,@RequestParam("backid") Integer backid){
        City getCity = cityService.findCityByGetid(getid);//查找租车城市
        City backCity = cityService.findCityByBackid(backid);//查询还车城市
        Citys citys = new Citys();
        citys.setGetCity(getCity);
        citys.setBackCity(backCity);
        if(getCity!=null && backCity!=null){
            return new ResponseBody2(1,citys);
        }
        return null;
    }
}
